﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SDF.Web.UI;

namespace SDF.Web.biz
{
    public partial class index : SDF.Web.UI.Page
    {

        string theme;
        string templateDir;
        TemplateHelper th;

        protected void Page_Load(object sender, EventArgs e)
        {
            InitTplInfo();
            LoadCommon();

            string type = Request["t"];

            switch (type)
            {
                case "about":
                    LoadAbout();
                    break;

                default:
                    LoadDefault();
                    break;
            }

        }

        //关于我们
        private void LoadAbout()
        {

        }

        //默认首页
        private void LoadDefault()
        {
            Display("index.html");
        }

        /// <summary>
        /// 初始化模板相关信息
        /// </summary>
        private void InitTplInfo()
        {
            string tplName = "default"; //TODO:

            theme = string.Format("/biz/template/{0}/", tplName);
            templateDir = Server.MapPath(string.Format("~/biz/template/{0}/", tplName));
            th = new TemplateHelper(templateDir);
        }

        //公共部分
        private void LoadCommon()
        {
            th.Put("theme", theme);

            //网站配置
            //TODO:

            //前台辅助对象
            th.Put("html", Html);
            th.Put("biz", Biz);
        }


        private void Display(string templateFile)
        {
            string templatePath = templateDir + templateFile;
            HttpContext.Current.Response.Write(th.BuildString(templateFile));
        }

    }
}